package com.atguigu.spzx.cart.controller;

import com.atguigu.spzx.cart.service.CartService;
import com.atguigu.spzx.model.entity.product.CartInfo;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Mahone
 */
@Tag(name = "购物车接口")
@RestController
@RequestMapping("/api/order/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @Operation(summary = "添加购物车")
    @GetMapping("/auth/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable("skuId") Long skuId, @PathVariable("skuNum") Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return Result.ok();
    }

    @Operation(summary = "购物车查询")
    @GetMapping("/auth/cartList")
    public Result<List<CartInfo>> cartList(){
       List<CartInfo> cartInfoList  = cartService.cartList();
        return Result.ok(cartInfoList);
    }

    @Operation(summary = "选中的购物车")
    @GetMapping("/auth/getAllCkecked")
    public Result<List<CartInfo>> getAllCkecked(){
        List<CartInfo> cartInfoList  = cartService.getAllCkecked();
        return Result.ok(cartInfoList);
    }

    @Operation(summary = "清空购物车")
    @GetMapping("/auth/deleteChecked")
    public Result deleteChecked(){
        cartService.deleteChecked();
        return Result.ok();
    }

}
